﻿using D.Medicalcare.Domain.Entities;
using D.Medicalcare.ErrorCode;
using D.Medicalcare.Read.API.Application.Command.PatientCommand;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace D.Medicalcare.Read.API.Controllers
{
    /// <summary>
    /// 就诊人管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    //[Authorize]
    public class PatientController : ControllerBase
    {
        /// <summary>
        /// 中介者
        /// </summary>
        private readonly IMediator mediator;
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="mediator">中介者</param>
        public PatientController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 就诊人显示
        /// </summary>
        /// <param name="request">参数</param>
        /// <returns>APIResult</returns>
        [HttpGet]
        public async Task<APIResult<List<Patient>>> GetPatient([FromQuery]GetPatientIdCommand request)
        {
            return await mediator.Send(request);

        }
        /// <summary>
        /// 获取就诊卡号
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<Patient>>> GetNoPatient([FromQuery]GetNoPatientCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 获取默认就诊人
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<Patient>> GetPatientM([FromQuery]GetPatientMCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }

        }

    }
}
